import { createStore, combineReducers, applyMiddleware } from 'redux'
import promiseMiddleware from 'redux-promise'
// import thunk from 'redux-thunk'
import rootReducer from './reducers'
import { composeWithDevTools } from 'redux-devtools-extension'

const middlewares = [promiseMiddleware]
if (process.env.NODE_ENV === 'development') {
  // GLOBAL.FormData = GLOBAL.originalFormData || GLOBAL.FormData
  GLOBAL.XMLHttpRequest = GLOBAL.originalXMLHttpRequest || GLOBAL.XMLHttpRequest // 关闭之后上传图片方可成功
  GLOBAL.WebSocket = GLOBAL.originalWebSocket || GLOBAL.WebSocket // 关闭之后上传图片方可成功
  // middlewares.push(require('redux-logger').createLogger())
}

// const sagaMiddleware = createSagaMiddleware()
// // 根据 reducer 初始化 store
// const store = createStore(appReducer, applyMiddleware(sagaMiddleware))
// sagaMiddleware.run(rootSaga)
const store = createStore(
  combineReducers(rootReducer),
  composeWithDevTools(applyMiddleware(...middlewares))
)

export default store
